﻿

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main()
{
	vector<int> arr = { 1, 3, -1, -3, 5, 3, 6, 7 };
	int k = 3;
	vector<int> ret;
	priority_queue<pair<int, int>> q;
	for (int i = 0; i < k; i++)
	{
		q.push({ arr[i], i });
	}

	//题目​​：给定数组和滑动窗口大小k，返回每次窗口移动时的最大值。
//​​示例​​：
//输入：nums = [1, 3, -1, -3, 5, 3, 6, 7], k = 3
//输出：[3, 3, 5, 5, 6, 7]

	ret.push_back(q.top().first);

	for (int i = k; i < arr.size(); i++)
	{
		q.push({ arr[i], i });
		while (q.top().second <= i - k)
		{
			q.pop();
		}
		ret.push_back(q.top().first);
	}

	for (auto e : ret)
	{
		cout << e << " ";
	}
	cout << endl;

	return 0;
}